class SearchController < ApplicationController
  def index
    @songs = Playlist.find_by_name("飙升榜").songs.take(20)
    @picks = []
    @favs = []
  end

  def query_text
    # 查询后按照字数排序
    if params[:text].present?
      @songs = Song.where("pinyin LIKE ?", "#{params[:text].upcase}%").order('LENGTH(name) ASC', pinyin: :asc).limit(200)
    else
      @songs = Playlist.find_by_name("飙升榜").songs.take(20)
    end
    @picks = []
    @favs = []
    respond_to do |format|
      format.js
    end
  end
end
